﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class WebPartControls_Document2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (GetClientIP().StartsWith("222.30") || GetClientIP().StartsWith("202.113") || GetClientIP().StartsWith("10") || GetClientIP().StartsWith("192.168") || GetClientIP().StartsWith("127.0"))
        {
            OfficeDataClassesDataContext dc = new OfficeDataClassesDataContext();
            var documents = from document in dc.Documents
                            where document.Document_id.Equals(Convert.ToInt32(Session["Document_id"]))
                            select new
                            {
                                标题 = document.Title,
                                内容 = document.Content
                            };

            News_Title.Text = Convert.ToString(documents.ToArray().ElementAt(0).标题);
            News_Content.Text = Convert.ToString(documents.ToArray().ElementAt(0).内容);
            PageTitle.Text = Convert.ToString(documents.ToArray().ElementAt(0).标题);
            dc.Dispose();
        }
        else
        {
            JavaScript.JSDialog.Alert(this, "您没有权限查看该文件！");

        }
    }
    private string GetClientIP()
    {
        string result = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
        if (null == result || result == String.Empty)
        {
            result = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
        } if (null == result || result == String.Empty)
        {
            result = HttpContext.Current.Request.UserHostAddress;
        }
        return result;
    }
}
